package lt.ntec.danblog.server.blog.model.gae;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import lt.ntec.danblog.server.core.model.Comment;
import lt.ntec.danblog.server.core.model.Commentable;
import lt.ntec.danblog.server.core.model.User;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;

@PersistenceCapable
class BlogComment implements Comment {

    @Persistent
    private Key userKey;
    private User user;
    @Persistent
    private Text content;
    @Persistent
    private Date date;
    @Persistent
    private Key parentKey;
    private Commentable parent;
    @Persistent
    private int voteDown;
    @Persistent
    private int voteUp;
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    BlogComment(User user, Commentable parent) {
        this.user = user;
        this.parent = parent;
    }

    @Override
    public User getUser() {
        return user;
    }

    @Override
    public String getContent() {
        return content.getValue();
    }

    @Override
    public void setContent(String content) {
        this.content = new Text(content);
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public Date getDate() {
        return date;
    }

    @Override
    public void setDate(Date date) {
        this.date = date;

    }

    @Override
    public Long getId() {
        return key.getId();
    }

    @Override
    public Commentable getParent() {
        return parent;
    }

    @Override
    public int getVoteUp() {
        return voteUp;
    }

    @Override
    public int getVoteDown() {
        return voteDown;
    }

    @Override
    public void addVoteDown() {
        voteDown++;
    }

    @Override
    public void addVoteUp() {
        voteUp++;
    }

    @Override
    public boolean hasUserVoted(User user) {
        // TODO Auto-generated method stub
        return false;
    }

    public void setParent(Commentable parent) {
        this.parent = parent;
    }

    public void setUserKey(Key key) {
        this.userKey = key;
    }

    public Key getUserKey() {
        return this.userKey;
    }

    public void setParentKey(Key key) {
        this.parentKey = key;
    }

    public Key getParentKey() {
        return this.parentKey;
    }
}
